using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
/// Summary description for dbConnection
/// </summary>
public class dbConnection
{    
    private sqlConnection.sqlConnection con = null;
    public dbConnection()
    {
        this.con = new sqlConnection.sqlConnection(ConfigurationManager.ConnectionStrings["Server"].ToString(), ConfigurationManager.ConnectionStrings["DatabaseName"].ToString(), ConfigurationManager.ConnectionStrings["User"].ToString(), ConfigurationManager.ConnectionStrings["Pass"].ToString());
        this.con.startConnect();
    }
    //---------getData----------------------------------------
    public DataTable getDataTable(string spName,SqlParameter[] p)
    {
        return this.con.getDataSet( p,spName).Tables[0];
    }
    public DataTable getDataTable(string spName,SqlParameter p)
    {
        return this.con.getDataSet( p,spName).Tables[0];
    }       
    public DataTable getDataTable(string spName)
    {
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = spName;
        return this.con.getDataSet(cmd).Tables[0];
    }

    //------------------Update-----------------------
    public int updateData( string spName, SqlParameter[] p)
    {
        return this.con.updateData(p, spName);
    }
    public int updateData( string spName, SqlParameter p)
    {
        return this.con.updateData(p, spName);
    }
    public int updateData(string spName)
    {
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = spName;
        return this.con.updateData(cmd);
    }

    //--------------get total----------------------
    public long getTotalTable(string spName)
    {
        return Convert.ToInt64(this.getDataTable(spName).Rows[0][0]);
    }
    public long getTotalTable( string spName, SqlParameter[] p)
    {
        return Convert.ToInt64(this.getDataTable( spName,p).Rows[0][0]);
    }
    public long getTotalTable( string spName, SqlParameter p)
    {
        return Convert.ToInt64(getDataTable( spName,p).Rows[0][0]);
    }    
}
